package edu.cdbi.view;

import tool.Tools;
import edu.cdbi.database.CourseManagement;
import edu.cdbi.model.instance.Course;


@SuppressWarnings("serial")
public class CoursePanel extends BasicPanel{
	
	public CoursePanel (){
		super();
		DTM.setColumnIdentifiers(new Object[]{"id", "teacher_id", "name"});
	}
	
	@Override
	protected void initialData() {
		addComponents.put("teacher_id", new BasicComponent());
		addComponents.put("name", new BasicComponent());
	}
	
	@Override
	protected void OKActionByAdd() {
		CourseManagement manager = new CourseManagement();
		if(manager.insert(addComponents.get("teacher_id").getText(), 
				addComponents.get("name").getText())  != null ){
			Tools.showMSG("新增課程成功!");
		}else{
			Tools.showError("新增課程失敗!");
		}
		addComponents.get("teacher_id").setText("");
		addComponents.get("name").setText("");
	}

	@Override
	protected void OKActionByModify() {
	}

	@Override
	protected void addAction() {
	}

	@Override
	protected void cancelActionByAdd() {
	}

	@Override
	protected void cancelActionByModify() {
	}

	@Override
	protected void deleteAction() {
	}

	@Override
	protected void modifyAction() {
	}

	@Override
	protected void update() {
	}

	@Override
	protected void viewAction() {
		Tools.removeTableItems(DTM);
		CourseManagement manager = new CourseManagement();
		for(Course course : manager.getList()){
			DTM.addRow(new Object[]{course.getId(), course.getTeacherId(), course.getName()});
		}
	}
	
}
